import React, {Component} from 'react'
import {connect} from 'react-redux';
import {setRoomInfoAction} from '@/store/action';

import ChatItem from './chatItem';
import Tabbar from "@/components/tabbar";

class Home extends Component {
  /**
   * @roomId 房间ID
   * @contacts 对方
   * @mine 自己
   * @chattingMsg 聊天记录
   * @hasRead      是否已读
   * @isTop        是否置顶
   * @notDisturb   是否勿扰
   * @msgType 消息类型：0 个人；1：群聊
   * */
  state = {
  }

  toChat(data) {
    this.props.history.push(`/chatting/${data.roomId}`)
  }

  componentDidMount() {
  }

  render() {
    const {roomInfo} = this.props;
    return (
      <section>
         <ul>
           {
             Object.keys(roomInfo).map(key => (
               <ChatItem room={roomInfo[key]} key={key}/>
             ))
           }
         </ul>

        <Tabbar/>
      </section>
    )
  }
}

const mapStateToProps = ({userInfo, roomInfo}) => {
  return {
    userInfo,
    roomInfo
  }
}
const mapDispatchToProps = dispatch => {
  return {
    setRoomInfo: (roomInfo) => dispatch(setRoomInfoAction(roomInfo))
  }
}
export default connect(mapStateToProps, mapDispatchToProps)(Home)


